package com.leo.sunnyweather.ui.places

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.ViewModel
import com.leo.sunnyweather.logic.Repository
import com.leo.sunnyweather.logic.model.Place

/**
 * Author: Leo Liao <lliao@midtronics.com>
 * Date: 02/02/2024 11:25
 * Description:
 */
class PlaceViewModel() : ViewModel() {
    private var queryPlace = MutableLiveData<String>()

    val placesList
        get() = _placesList

    private val _placesList = ArrayList<Place>()

    val placesLiveData
        get() = _placesLiveData

    private val _placesLiveData =
        Transformations.switchMap(queryPlace) { str -> Repository.searchPlaces(str) }

    fun queryPlace(query: String) {
        queryPlace.value = query
    }
}